package com.deryun.tyl.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.deryun.tyl.bean.Policy;
import com.deryun.tyl.bean.User;
import com.deryun.tyl.dao.impl.PolicyDaoImpl;

@Service("policyServiceImpl")
public class PolicyServiceImpl {
	
	@Resource(name="policyDaoImpl")
	private PolicyDaoImpl policyDaoImpl;
	
	public int addPolicy(HttpServletRequest request,Policy policy){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		policy.setPublishDate(df.format(new Date()));
		policy.setPublishMan(((User)request.getSession().getAttribute("user")).getContactMan());
		policy.setPublishUserId(((User)request.getSession().getAttribute("user")).getId().toString());
		return policyDaoImpl.addPolicy(policy);
	}
	
	public List<Policy> getAllPolicy(){
		return policyDaoImpl.getAllPolicy();
	}
	
	public List<Policy> getUserPolicy(String publishUserId){
		return policyDaoImpl.getUserPolicy(publishUserId);
	}
	
	public int deletePolicy(int id){
		return policyDaoImpl.deletePolicy(id);
	}
	
	public List<Policy> getNewPolicys(){
		return policyDaoImpl.getNewPolicys();
	}
	
	public int modifyPolicy(Policy policy){
		return policyDaoImpl.modifyPolicy(policy);
	}
	
	public Policy getPolicyById(int id){
		return policyDaoImpl.getPolicyById(id);
	}
	
	public int setResult(Policy policy){
		return policyDaoImpl.setResult(policy);
	}
}
